package com.od.controller;

import com.od.entity.Education;
import com.od.service.EducationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("education")
@CrossOrigin
public class EducationController {

    @Autowired
    private EducationService educationService;

    @RequestMapping("getEducationById")
    @ResponseBody
    public List<Education> getEducationById(int educationResume) {
        return educationService.getEducationById(educationResume);
    }

    @RequestMapping("addEducation")
    @ResponseBody
    public int addEducation(@RequestBody Education education) {
        System.out.println(education);
        return educationService.addEducation(education);
    }

    @RequestMapping("updateEducationById")
    @ResponseBody
    public int updateEducationById(@RequestBody Education education) {
        System.out.println(education);
        return educationService.updateEducationById(education);
    }

    @RequestMapping("deleteEducationById")
    @ResponseBody
    public int deleteEducationById(@RequestBody Map<String, Integer> educationData) {
        int educationId = educationData.get("educationId");
        return educationService.deleteEducationById(educationId);
    }

}
